package com.prism.cluster;

/**
 *
 * @author fola
 *
 */
public class KayMeans {
	private ClusterSet next;
	private ClusterSet prev;

	/**
	 *
	 * @param kay
	 */
	public KayMeans(ClusterSet kay){
		setPrev(kay);
		setNext(new ClusterSet(getPrev()));
		iterate();

	}

	private void iterate(){
		while(noChange()){
			setPrev(getNext());
			setNext(new ClusterSet(getPrev()));
		}
	}

	private boolean noChange(){
		return getNext().equals(getPrev());
	}
	private void setNext(ClusterSet next) {
		this.next = next;
	}

	public ClusterSet getNext() {
		return next;
	}

	private void setPrev(ClusterSet prev) {
		this.prev = prev;
	}

	public ClusterSet getPrev() {
		return prev;
	}

	public String toString(){
		StringBuilder sb = new StringBuilder();
		for(Cluster clust : getNext().getClusters()){
			sb.append(clust.getCentroid() + "\t"+ clust.size());
			sb.append("\n");
		}

		return sb.toString();
	}
}
